<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  user_model.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-21.
//  Copyright 2011 lishuzu. All rights reserved.
// 


class Invite_model extends CI_Model
{
		function __construct(){
			parent::__construct();
			$this->load->model('user_model');
			
			$this->user = $this->session->userdata('user') ? $this->session->userdata('user') : '';
			$this->uid = $this->uri->segment(3) ? intval($this->uri->segment(3)) : $this->user['uid'];
		}
		//检验邀请码是否有效
		function checkcode($email, $code){
			$where = array();
			if ($code) {
				$where = array(
					'email' => $email,
					'code' => $code,
					'status' => '0'
					);
				$this->db->where($where);
				$count = $this->db->count_all_results('invite');
				return $count;
			}
			return false;
		}
		function getinvitecode($key, $value){
			if ($key) {
				$this->db->where($key, $value);
				$query = $this->db->get('invite');
				$data = $query->row_array();
				if ($data) {
					return $data;
				}
			}
			return false;
		}
		
		function add($data){
			if ($data) {
				$this->db->insert('invite', $data);
				return $this->db->insert_id();
			}else{
				return false;
			}
		}
		
		function delete($email, $code){
			if ($email && $code) {
				$where = array(
					'email' => $email,
					'code' => $code,
					'status' => '0'
					);
				$this->db->where($where);
				$this->db->update('invite', array('status' => '-1'));
				return $this->db->affected_rows();
			}
			return false;
		}
}
?>